package Stream;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Collectors;

//筛选出年龄大于24的人,放入map集合中
public class Test2 {
    public static void main(String[] args) {
        ArrayList<String>arrayList=new ArrayList<>();
        Collections.addAll(arrayList,"张三,23","李四,24","王五,25" );
        Map<String,Integer>map= arrayList.stream().filter(new Predicate<String>() {
            @Override
            public boolean test(String s) {
//                return Integer.parseInt(s.split(",")[1])>=24;
                String[] split = s.split(",");
                return Integer.parseInt(split[1])>=24;
            }
        }).collect(Collectors.toMap(new Function<String, String>() {
            @Override
            public String apply(String s) {
                return s.split(",")[0];
            }
        }, new Function<String, Integer>() {
            @Override
            public Integer apply(String s) {
                return Integer.parseInt(s.split(",")[1]);
            }
        }));
        map.entrySet().stream().forEach(new Consumer<Map.Entry<String, Integer>>() {
            @Override
            public void accept(Map.Entry<String, Integer> stringIntegerEntry) {
                System.out.println(stringIntegerEntry.getKey()+"--"+stringIntegerEntry.getValue());
            }
        });
    }
}
